package cqut.wys.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * --------神兽出没--------/
 *   ┌─┐     ┌─┐
 * ┌─┘─┴─────┘─┴─┐
 * │      ─      │
 * │  ┬─┘   └─┬  │
 * │             │
 * │      ┴      │  Code is far away from bug with the animal protecting
 * └───┐      ┌──┘  神兽保佑,代码无bug
 *     │      │
 *     │      └──────┐
 *     │             ├┐
 *     │             ┌┘
 *     └┐ ┐ ┌───┬─┐ ┌┘
 *      │ ┤ ┤   │ ┤ ┤
 *      └─┴─┘   └─┴─┘
 * --------感觉萌萌哒--------/
 *
 * @author wys
 * @date 2018/11/16.
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @GetMapping("/addUser")
    public void addUser() {
       this.add();
    }

    private void add() {
        AtomicInteger atomicInteger = new AtomicInteger(7);
        while (atomicInteger.get() < 1000) {
            String sql = "INSERT INTO user (id,name, age, email) VALUES ("+ atomicInteger.getAndIncrement() + ",'Tom'," + atomicInteger.getAndIncrement() + ",'test@baomidou.com')";
            jdbcTemplate.execute(sql);
        }
    }

    @GetMapping("/list")
    public List<Map<String, Object>> listUser(){
        List<Map<String, Object>> list= jdbcTemplate.queryForList("select * from user");
        return list;
    }
}
